<!--客户订单 表格搜索组件，用于区分订单的各项状态下的表单查询 -->
<template>
  <div class="searchFormComp-component">
    <!-- 审核中 -->
    <template v-if="tabVal == '1'">
      <el-form
        :model="queryParams1"
        ref="queryForm"
        size="mini"
        :inline="true"
        label-width="100px"
      >
        <el-form-item label-width="50" label="订单状态">
          <el-select v-model="queryParams1.auditType">
            <el-option label="已驳回" value="0"></el-option>
            <el-option label="待审核" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label-width="60" label="下单时间">
          <QuickFilterDate :disableArr="[4, 7]" v-model="datetimeArr1" />
        </el-form-item>

        <el-form-item label-width="50" label="订单来源">
          <el-select
            v-model="queryParams1.orderSource"
            placeholder="请选择订单来源"
          >
            <el-option label="全部" :value="null"></el-option>
            <el-option label="客户下单" value="1"></el-option>
            <el-option label="营销下单" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label-width="50" label="订单类型">
          <el-select
            v-model="queryParams1.orderType"
            placeholder="请选择订单类型"
          >
            <el-option label="全部" :value="null"></el-option>
            <el-option label="来料加工" value="1"></el-option>
            <el-option label="普通订单" value="2"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label-width="70" label="预付款类型">
          <el-select
            v-model="queryParams1.advance"
            placeholder="请选择预付款类型"
          >
            <el-option label="全部" :value="null"></el-option>
            <el-option label="非预付" value="1"></el-option>
            <el-option label="预付定金" value="2"></el-option>
            <el-option label="预付全款" value="3"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label-width="30" label="工程ID">
          <el-input
            v-model="queryParams1.engineeringId"
            placeholder="请输入工程ID"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="50" label="工程名称">
          <el-input
            v-model="queryParams1.engineeringName"
            placeholder="请输入工程名称"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="50" label="客户名称">
          <el-input
            v-model="queryParams1.customerName"
            placeholder="客户名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="getFormDataFunc"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery(1)"
            >重置</el-button
          >
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="$emit('handleAdd')"
            v-hasPermi="['system:orders:add']"
            >新增</el-button
          >
        </el-form-item>
      </el-form>
    </template>
    <!-- 待生产 -->
    <template v-if="tabVal == '2'">
      <el-form
        :model="queryParams2"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="100px"
      >
        <el-form-item label="计划开工时间">
          <QuickFilterDate
            :disableArr="[2, 3, 4, 5, 6]"
            v-model="datetimeArr2"
          />
        </el-form-item>
        <el-form-item label-width="50" label="订单类型">
          <el-select
            v-model="queryParams2.orderType"
            placeholder="请选择订单类型"
          >
            <el-option label="全部" :value="null"></el-option>
            <el-option label="来料加工" value="1"></el-option>
            <el-option label="普通订单" value="2"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label-width="60" label="预付款类型">
          <el-select
            v-model="queryParams2.advance"
            placeholder="请选择预付款类型"
          >
            <el-option label="全部" :value="null"></el-option>
            <el-option label="非预付" value="1"></el-option>
            <el-option label="预付定金" value="2"></el-option>
            <el-option label="预付全款" value="3"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label-width="40" label="工程ID">
          <el-input
            v-model="queryParams2.engineeringId"
            placeholder="请输入工程ID"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="50" label="工程名称">
          <el-input
            v-model="queryParams2.engineeringName"
            placeholder="请输入工程名称"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="60" label="施工单位名称">
          <el-input
            v-model="queryParams2.construction_unit"
            placeholder="请输入施工单位名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="getFormDataFunc"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery(2)"
            >重置</el-button
          >
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="$emit('handleAdd')"
            v-hasPermi="['system:orders:add']"
            >新增</el-button
          >
          <el-button size="mini" @click="jumpAutomatic">自动排产</el-button>
          <el-button size="mini" @click="$emit('generateTaskFn')"
            >加入生产任务</el-button
          >
        </el-form-item>
      </el-form>
    </template>
    <!-- 生产中 -->
    <template v-if="tabVal == '3'">
      <el-form
        :model="queryParams3"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="100px"
      >
        <el-form-item label-width="40" label="工程ID">
          <el-input
            v-model="queryParams3.engineeringId"
            placeholder="请输入工程ID"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="50" label="工程名称">
          <el-input
            v-model="queryParams3.engineeringName"
            placeholder="请输入工程名称"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="60" label="施工单位名称">
          <el-input
            v-model="queryParams3.construction_unit"
            placeholder="请输入施工单位名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="getFormDataFunc"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery(3)"
            >重置</el-button
          >
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="$emit('handleAdd')"
            v-hasPermi="['system:orders:add']"
            >新增</el-button
          >
        </el-form-item>
      </el-form>
    </template>
    <!-- 生产暂停 -->
    <template v-if="tabVal == '4'">
      <el-form
        :model="queryParams4"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="100px"
      >
        <el-form-item label-width="50" label="暂停时间">
          <QuickFilterDate :disableArr="[4, 7]" v-model="datetimeArr4" />
        </el-form-item>
        <el-form-item label-width="40" label="工程ID">
          <el-input
            v-model="queryParams4.engineeringId"
            placeholder="请输入工程ID"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="50" label="工程名称">
          <el-input
            v-model="queryParams4.engineeringName"
            placeholder="请输入工程名称"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="60" label="施工单位名称">
          <el-input
            v-model="queryParams4.construction_unit"
            placeholder="请输入施工单位名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="getFormDataFunc"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery(4)"
            >重置</el-button
          >
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="$emit('handleAdd')"
            v-hasPermi="['system:orders:add']"
            >新增</el-button
          >
        </el-form-item>
      </el-form>
    </template>

    <!-- 订单完工 -->
    <template v-if="tabVal == '5'">
      <el-form
        :model="queryParams5"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="100px"
      >
        <el-form-item label-width="50" label="暂停时间">
          <QuickFilterDate :disableArr="[4, 7]" v-model="datetimeArr5" />
        </el-form-item>
        <el-form-item label-width="30" label="工程ID">
          <el-input
            v-model="queryParams5.engineeringId"
            placeholder="请输入工程ID"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="50" label="工程名称">
          <el-input
            v-model="queryParams5.engineeringName"
            placeholder="请输入工程名称"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="60" label="施工单位名称">
          <el-input
            v-model="queryParams5.construction_unit"
            placeholder="请输入施工单位名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="getFormDataFunc"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery(5)"
            >重置</el-button
          >
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="$emit('handleAdd')"
            v-hasPermi="['system:orders:add']"
            >新增</el-button
          >
        </el-form-item>
      </el-form>
    </template>

    <!-- 订单过期 -->
    <template v-if="tabVal == '6'">
      <el-form
        :model="queryParams6"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="100px"
      >
        <el-form-item label-width="50" label="过期时间">
          <QuickFilterDate :disableArr="[4, 7]" v-model="datetimeArr6" />
        </el-form-item>
        <el-form-item label-width="40" label="工程ID">
          <el-input
            v-model="queryParams6.engineeringId"
            placeholder="请输入工程ID"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="50" label="工程名称">
          <el-input
            v-model="queryParams6.engineeringName"
            placeholder="请输入工程名称"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="60" label="施工单位名称">
          <el-input
            v-model="queryParams6.construction_unit"
            placeholder="请输入施工单位名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="getFormDataFunc"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery(6)"
            >重置</el-button
          >
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="$emit('handleAdd')"
            v-hasPermi="['system:orders:add']"
            >新增</el-button
          >
        </el-form-item>
      </el-form>
    </template>

    <!-- 订单取消 -->
    <template v-if="tabVal == '7'">
      <el-form
        :model="queryParams7"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="100px"
      >
        <el-form-item label-width="50" label="取消时间">
          <QuickFilterDate :disableArr="[4, 7]" v-model="datetimeArr7" />
        </el-form-item>
        <el-form-item label-width="40" label="工程ID">
          <el-input
            v-model="queryParams7.engineeringId"
            placeholder="请输入工程ID"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="50" label="工程名称">
          <el-input
            v-model="queryParams7.engineeringName"
            placeholder="请输入工程名称"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="60" label="施工单位名称">
          <el-input
            v-model="queryParams7.construction_unit"
            placeholder="请输入施工单位名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="getFormDataFunc"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery(7)"
            >重置</el-button
          >
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="$emit('handleAdd')"
            v-hasPermi="['system:orders:add']"
            >新增</el-button
          >
        </el-form-item>
      </el-form>
    </template>
  </div>
</template>

<script>
import QuickFilterDate from "@/components/QuickFilterDate";
export default {
  components: {
    QuickFilterDate,
  },
  props: {
    tabVal: {
      type: String,
      default: "1",
    },
  },
  data() {
    return {
      datetimeArr1: [],
      datetimeArr2: [],
      datetimeArr4: [],
      datetimeArr5: [],
      datetimeArr6: [],
      datetimeArr7: [],
      queryParams1: {
        auditType: "1",
        //审核中
      },
      queryParams2: {
        //待生产
      },
      queryParams3: {
        //生产中
      },
      queryParams4: {
        //生成暂停
      },
      queryParams5: {
        //订单完工
      },
      queryParams6: {
        //订单过期
      },
      queryParams7: {
        //订单取消
      },
    };
  },
  methods: {
    //查询,表单的数据
    getFormDataFunc() {
      //处理日期时间
      let tab = this.tabVal;
      if (
        this["datetimeArr" + tab] &&
        this["datetimeArr" + tab] instanceof Array &&
        this["datetimeArr" + tab].length > 0
      ) {
        let [startTime, endTime] = this["datetimeArr" + tab];
        this["queryParams" + tab].startTime = startTime;
        this["queryParams" + tab].endTime = endTime;
      } else {
        this["queryParams" + tab].startTime = "";
        this["queryParams" + tab].endTime = "";
      }
      let formData = this["queryParams" + tab];
      this.$emit("onSearchFunc", formData);
    },
    getSearchformData(_tab) {
      let tab = _tab;
      if (tab == 0) return {}; //全部 不需要查询，
      if (tab == 9) return {}; //全部 不需要查询，
      if (
        this["datetimeArr" + tab] &&
        this["datetimeArr" + tab] instanceof Array &&
        this["datetimeArr" + tab].length > 0
      ) {
        let [startTime, endTime] = this["datetimeArr" + tab];
        this["queryParams" + tab].startTime = startTime;
        this["queryParams" + tab].endTime = endTime;
      } else {
        this["queryParams" + tab].startTime = "";
        this["queryParams" + tab].endTime = "";
      }
      let formData = this["queryParams" + tab];
      return formData;
    },
    /** 重置按钮操作 */
    resetQuery(index) {
      //this.resetForm("queryForm");
      this["datetimeArr" + index] = this.$options.data()["datetimeArr" + index];
      this["queryParams" + index] = this.$options.data()["queryParams" + index];
      this.getFormDataFunc();
    },
    jumpAutomatic() {
      // 进入自动排产
      this.$router.push("/order/automaticScheduling");
    },
    handelBtn(type) {
      this.queryParams1.auditType = type;
    },
  },
};
</script>

<style lang="scss" scoped>
.searchFormComp-component {
}
</style>